home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bluep.swf / scripts / __Packages / SoundPlayer.as < prev    next >
Text File  |  2013-04-24  |  4KB  |  143 lines

  1. class SoundPlayer
  2. {
  3.    function SoundPlayer()
  4.    {
  5.       this.channelsAvailable = new Array(true,true,true);
  6.       this.channel1 = new Sound();
  7.       this.channel2 = new Sound();
  8.       this.channel3 = new Sound();
  9.       this.externalSoundVolume = 100;
  10.    }
  11.    function CleanSounds(intIndex)
  12.    {
  13.       this.channelsAvailable[intIndex] = true;
  14.    }
  15.    function PlaySound(linkIdentifier)
  16.    {
  17.       if(_global.soundOn == true)
  18.       {
  19.          var thisRef = this;
  20.          if(this.channelsAvailable[0] == true)
  21.          {
  22.             this.channelsAvailable[0] = false;
  23.             delete this.channel1;
  24.             this.channel1 = new Sound();
  25.             this.channel1.attachSound(linkIdentifier);
  26.             this.channel1.setVolume(100);
  27.             this.channel1.start(0,0);
  28.             this.channel1.onSoundComplete = function()
  29.             {
  30.                thisRef.CleanSounds(0);
  31.             };
  32.          }
  33.          else if(this.channelsAvailable[1] == true)
  34.          {
  35.             this.channelsAvailable[1] = false;
  36.             delete this.channel2;
  37.             this.channel2 = new Sound();
  38.             this.channel2.attachSound(linkIdentifier);
  39.             this.channel2.setVolume(100);
  40.             this.channel2.start(0,0);
  41.             this.channel2.onSoundComplete = function()
  42.             {
  43.                thisRef.CleanSounds(1);
  44.             };
  45.          }
  46.          else
  47.          {
  48.             this.channelsAvailable[0] = false;
  49.             delete this.channel1;
  50.             this.channel1 = new Sound();
  51.             this.channel1.attachSound(linkIdentifier);
  52.             this.channel1.setVolume(100);
  53.             this.channel1.start(0,0);
  54.             this.channel1.onSoundComplete = function()
  55.             {
  56.                thisRef.CleanSounds(0);
  57.             };
  58.          }
  59.       }
  60.    }
  61.    function PlayBubbleSound(linkIdentifier)
  62.    {
  63.       if(_global.soundOn == true)
  64.       {
  65.          var thisRef = this;
  66.          if(this.channelsAvailable[2] == true)
  67.          {
  68.             this.channelsAvailable[2] = false;
  69.             delete this.channel3;
  70.             this.channel3 = new Sound();
  71.             this.channel3.attachSound(linkIdentifier);
  72.             this.channel3.setVolume(100);
  73.             this.channel3.start(0,0);
  74.             this.channel3.onSoundComplete = function()
  75.             {
  76.                thisRef.CleanSounds(2);
  77.             };
  78.          }
  79.       }
  80.    }
  81.    function PlayExternalSound(urlPath)
  82.    {
  83.       var thisRef = this;
  84.       if(this.channelsAvailable[0] == true)
  85.       {
  86.          this.channelsAvailable[0] = false;
  87.          delete this.channel1;
  88.          this.channel1 = new Sound();
  89.          this.channel1.loadSound(urlPath,false);
  90.          this.channel1.setVolume(this.externalSoundVolume);
  91.          this.channel1.onLoad = function(loadedOK)
  92.          {
  93.             if(loadedOK)
  94.             {
  95.                this.start();
  96.             }
  97.          };
  98.          this.channel1.onSoundComplete = function()
  99.          {
  100.             thisRef.CleanSounds(0);
  101.          };
  102.       }
  103.       else if(this.channelsAvailable[1] == true)
  104.       {
  105.          this.channelsAvailable[1] = false;
  106.          delete this.channel2;
  107.          this.channel2 = new Sound();
  108.          this.channel2.loadSound(urlPath,false);
  109.          this.channel2.setVolume(this.externalSoundVolume);
  110.          this.channel2.onLoad = function(loadedOK)
  111.          {
  112.             if(loadedOK)
  113.             {
  114.                this.start();
  115.             }
  116.          };
  117.          this.channel2.onSoundComplete = function()
  118.          {
  119.             thisRef.CleanSounds(1);
  120.          };
  121.       }
  122.       else
  123.       {
  124.          this.channelsAvailable[0] = false;
  125.          delete this.channel1;
  126.          this.channel1 = new Sound();
  127.          this.channel1.loadSound(urlPath,false);
  128.          this.channel1.setVolume(this.externalSoundVolume);
  129.          this.channel1.onLoad = function(loadedOK)
  130.          {
  131.             if(loadedOK)
  132.             {
  133.                this.start();
  134.             }
  135.          };
  136.          this.channel1.onSoundComplete = function()
  137.          {
  138.             thisRef.CleanSounds(0);
  139.          };
  140.       }
  141.    }
  142. }
  143.